package cn.iocoder.yudao.module.vos.service.activitytask;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.vos.controller.admin.activitytask.vo.*;
import cn.iocoder.yudao.module.vos.dal.dataobject.activitytask.ActivityTaskDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.vos.dal.mysql.activitytask.ActivityTaskMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.vos.enums.ErrorCodeConstants.*;

/**
 * 活动任务详情 Service 实现类
 *
 * @author shijun
 */
@Service
@Validated
public class ActivityTaskServiceImpl implements ActivityTaskService {

    @Resource
    private ActivityTaskMapper activityTaskMapper;

    @Override
    public Long createActivityTask(ActivityTaskSaveReqVO createReqVO) {
        // 插入
        ActivityTaskDO activityTask = BeanUtils.toBean(createReqVO, ActivityTaskDO.class);
        activityTaskMapper.insert(activityTask);

        // 返回
        return activityTask.getId();
    }

    @Override
    public void updateActivityTask(ActivityTaskSaveReqVO updateReqVO) {
        // 校验存在
        validateActivityTaskExists(updateReqVO.getId());
        // 更新
        ActivityTaskDO updateObj = BeanUtils.toBean(updateReqVO, ActivityTaskDO.class);
        activityTaskMapper.updateById(updateObj);
    }

    @Override
    public void deleteActivityTask(Long id) {
        // 校验存在
        validateActivityTaskExists(id);
        // 删除
        activityTaskMapper.deleteById(id);
    }

    @Override
        public void deleteActivityTaskListByIds(List<Long> ids) {
        // 删除
        activityTaskMapper.deleteByIds(ids);
        }


    private void validateActivityTaskExists(Long id) {
        if (activityTaskMapper.selectById(id) == null) {
            throw exception(ACTIVITY_TASK_NOT_EXISTS);
        }
    }

    @Override
    public ActivityTaskDO getActivityTask(Long id) {
        return activityTaskMapper.selectById(id);
    }

    @Override
    public PageResult<ActivityTaskDO> getActivityTaskPage(ActivityTaskPageReqVO pageReqVO) {
        return activityTaskMapper.selectPage(pageReqVO);
    }

}